package Test;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CheckBoxTest {
    private static void CheckBox(){
        JFrame frame = new JFrame("复选框");
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(500,400);
        frame.setLocation(300,200);
        JLabel label = new JLabel("HELLO WORLD",JLabel.CENTER);
        label.setFont(new Font("宋体",Font.PLAIN,20));
        JPanel panel = new JPanel();
        JCheckBox checkBox1 = new JCheckBox("男");
        JCheckBox checkBox2 = new JCheckBox("女");
        ActionListener listener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int border = 0;
                if (checkBox1.isSelected())
                    border += Font.BOLD;
                if (checkBox2.isSelected())
                    border+=Font.ITALIC;
               label.setFont(new Font("宋体",border,20));
            }
        };
        checkBox1.addActionListener(listener);
        checkBox2.addActionListener(listener);
        panel.add(checkBox1);
        panel.add(checkBox2);
        frame.add(label);
        frame.add(panel,BorderLayout.PAGE_END);
    }

    public static void main(String[] args) {
       SwingUtilities.invokeLater(CheckBoxTest::CheckBox);
    }
}
